/**
 * 
 */
	var sh = $(".sh");
    var sz = $(".sz");
    var nasdaq = $(".nasdaq");
    var dji = $(".dji");
    var url ="http://"+ window.location.host +$("#wrapper-nav").attr("contextPath") + "/ajax/refreshIndex.do";
//    var url = window.location.origin + "/refreshIndex.do";
    $(function(){
    	setInterval(refresh,2000); 
    });
    function refresh(){
    	 $.ajax({
    	        url: url,
    	        cache: false,
    	        type: "GET",
    	        dataType: "json",
    	        success: function(result){
    	        	/**
    	        	 * 沪深指数
    	        	 */
    	        	if(result != undefined && result.success && result.data.length == 4 ){
    	        		if(result.data[0].todayIncrePercent != undefined && result.data[0].todayIncrePercent >=0){
    	        			if(sh.hasClass("green")){
    	        				sh.removeClass("green");
    	        			}
    	        			sh.addClass("red");
    	        			sh.find(".index").html(result.data[0].priceNow);
            	        	sh.find(".incre").html("上涨:" + result.data[0].todayIncrePercent + "%");
    	        		}else{
    	        			if(sh.hasClass("red")){
    	        				sh.removeClass("red");
    	        			}
    	        			sh.addClass("green");
    	        			sh.find(".index").html(result.data[0].priceNow);
            	        	sh.find(".incre").html("下跌:" + result.data[0].todayIncrePercent + "%");
    	        		}
    	        		
    	        		/**
    	        		 * 深证指数
    	        		 */
    	        		if(result.data[1].todayIncrePercent != undefined && result.data[1].todayIncrePercent >=0){
    	        			if(sz.hasClass("green")){
    	        				sz.removeClass("green");
    	        			}
    	        			sz.addClass("red");
    	        			sz.find(".index").html(result.data[1].priceNow);
    	        			sz.find(".incre").html("上涨:" + result.data[1].todayIncrePercent + "%");
    	        		}else{
    	        			if(sz.hasClass("red")){
    	        				sz.removeClass("red");
    	        			}
    	        			sz.addClass("green");
    	        			sz.find(".index").html(result.data[1].priceNow);
    	        			sz.find(".incre").html("下跌:" + result.data[1].todayIncrePercent + "%");
    	        		}
    	        		
    	        		/**
    	        		 * 纳斯达克
    	        		 */
    	        		if(result.data[2].todayIncrePercent != undefined && result.data[2].todayIncrePercent >=0){
    	        			if(nasdaq.hasClass("green")){
    	        				nasdaq.removeClass("green");
    	        			}
    	        			nasdaq.addClass("red");
    	        			nasdaq.find(".index").html(result.data[2].priceNow);
    	        			nasdaq.find(".incre").html("上涨:" + result.data[2].todayIncrePercent + "%");
    	        		}else{
    	        			if(nasdaq.hasClass("red")){
    	        				nasdaq.removeClass("red");
    	        			}
    	        			nasdaq.addClass("green");
    	        			nasdaq.find(".index").html(result.data[2].priceNow);
    	        			nasdaq.find(".incre").html("下跌:" + result.data[2].todayIncrePercent + "%");
    	        		}
    	        		
    	        		/**
    	        		 * 道琼斯
    	        		 */
    	        		if(result.data[3].todayIncrePercent != undefined && result.data[3].todayIncrePercent >=0){
    	        			if(dji.hasClass("green")){
    	        				dji.removeClass("green");
    	        			}
    	        			dji.addClass("red");
    	        			dji.find(".index").html(result.data[3].priceNow);
    	        			dji.find(".incre").html("上涨:" + result.data[3].todayIncrePercent + "%");
    	        		}else{
    	        			if(dji.hasClass("red")){
    	        				dji.removeClass("red");
    	        			}
    	        			dji.addClass("green");
    	        			dji.find(".index").html(result.data[3].priceNow);
    	        			dji.find(".incre").html("下跌:" + result.data[3].todayIncrePercent + "%");
    	        		}
    	        	}
    	        	
    	        },
    	        error: function(result){
    	        	//alert("跑批失败");
    	        }
    	    });
    }